From 113654b9fe3fe96e923875e726ddb8ad2b430460 Mon Sep 17 00:00:00 2001 From: Christian Limpach Date: Sun, 20 Aug 2006 23:59:34 +0100 Subject: [PATCH] [qemu] hdparm tunable IDE write cache for HVM qemu 0.8.2 has a flush callback to the storage backends, so now it is possible to implement hdparm tunable IDE write cache enable/disable for guest domains, allowing people to pick speed or data consistency on a case by case basis. As an added benefit, really large LBA48 IOs will now no longer be broken up into smaller IOs on the host side. From: Rik van Riel Signed-off-by: Christian Limpach --- tools/ioemu/block-bochs.c | 2 +- tools/ioemu/block-cloop.c | 2 +- tools/ioemu/block-cow.c | 2 +- tools/ioemu/block-qcow.c | 2 +- tools/ioemu/block-vmdk.c | 2 +- tools/ioemu/block.c | 2 +- tools/ioemu/hw/ide.c | 17 +++++++++++++++++ 7 files changed, 23 insertions(+), 6 deletions(-) diff --git a/tools/ioemu/block-bochs.c b/tools/ioemu/block-bochs.c index d82c239281..62317aff38 100644 --- a/tools/ioemu/block-bochs.c +++ b/tools/ioemu/block-bochs.c @@ -91,7 +91,7 @@ static int bochs_open(BlockDriverState *bs, const char *filename) int fd, i; struct bochs_header bochs; - fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC); + fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE); if (fd < 0) { fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE); if (fd < 0) diff --git a/tools/ioemu/block-cloop.c b/tools/ioemu/block-cloop.c index 0f56685664..c617e1b64b 100644 --- a/tools/ioemu/block-cloop.c +++ b/tools/ioemu/block-cloop.c @@ -55,7 +55,7 @@ static int cloop_open(BlockDriverState *bs, const char *filename) BDRVCloopState *s = bs->opaque; uint32_t offsets_size,max_compressed_block_size=1,i; - s->fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE | O_SYNC); + s->fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE); if (s->fd < 0) return -1; bs->read_only = 1; diff --git a/tools/ioemu/block-cow.c b/tools/ioemu/block-cow.c index ff73cac0f9..6af8b74975 100644 --- a/tools/ioemu/block-cow.c +++ b/tools/ioemu/block-cow.c @@ -69,7 +69,7 @@ static int cow_open(BlockDriverState *bs, const char *filename) struct cow_header_v2 cow_header; int64_t size; - fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC); + fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE); if (fd < 0) { fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE); if (fd < 0) diff --git a/tools/ioemu/block-qcow.c b/tools/ioemu/block-qcow.c index d7fd9d534b..e5b52fb861 100644 --- a/tools/ioemu/block-qcow.c +++ b/tools/ioemu/block-qcow.c @@ -95,7 +95,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename) int fd, len, i, shift; QCowHeader header; - fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC); + fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE); if (fd < 0) { fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE); if (fd < 0) diff --git a/tools/ioemu/block-vmdk.c b/tools/ioemu/block-vmdk.c index 3143077f49..4cc3db84a1 100644 --- a/tools/ioemu/block-vmdk.c +++ b/tools/ioemu/block-vmdk.c @@ -96,7 +96,7 @@ static int vmdk_open(BlockDriverState *bs, const char *filename) uint32_t magic; int l1_size; - fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC); + fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE); if (fd < 0) { fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE); if (fd < 0) diff --git a/tools/ioemu/block.c b/tools/ioemu/block.c index 210cb7a51e..00444abb19 100644 --- a/tools/ioemu/block.c +++ b/tools/ioemu/block.c @@ -685,7 +685,7 @@ static int raw_open(BlockDriverState *bs, const char *filename) int rv; #endif - fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC); + fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE); if (fd < 0) { fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE); if (fd < 0) diff --git a/tools/ioemu/hw/ide.c b/tools/ioemu/hw/ide.c index 92d33ef6e0..8b070cc0cc 100644 --- a/tools/ioemu/hw/ide.c +++ b/tools/ioemu/hw/ide.c @@ -305,6 +305,7 @@ typedef struct IDEState { PCIDevice *pci_dev; struct BMDMAState *bmdma; int drive_serial; + int write_cache; /* ide regs */ uint8_t feature; uint8_t error; @@ -789,6 +790,9 @@ static void ide_sector_write(IDEState *s) } ide_set_sector(s, sector_num + n); + if (!s->write_cache) + bdrv_flush(s->bs); + #ifdef TARGET_I386 if (win2k_install_hack && ((++s->irq_count % 16) == 0)) { /* It seems there is a bug in the Windows 2000 installer HDD @@ -863,6 +867,10 @@ static int ide_write_dma_cb(IDEState *s, transfer_size -= len; phys_addr += len; } + /* Ensure the data hit disk before telling the guest OS so. */ + if (!s->write_cache) + bdrv_flush(s->bs); + return transfer_size1 - transfer_size; } @@ -1672,7 +1680,15 @@ static void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) /* XXX: valid for CDROM ? */ switch(s->feature) { case 0x02: /* write cache enable */ + s->write_cache = 1; + s->status = READY_STAT | SEEK_STAT; + ide_set_irq(s); + break; case 0x82: /* write cache disable */ + s->write_cache = 0; + s->status = READY_STAT | SEEK_STAT; + ide_set_irq(s); + break; case 0xaa: /* read look-ahead enable */ case 0x55: /* read look-ahead disable */ s->status = READY_STAT | SEEK_STAT; @@ -2090,6 +2106,7 @@ static void ide_init2(IDEState *ide_state, s->irq = irq; s->sector_write_timer = qemu_new_timer(vm_clock, ide_sector_write_timer_cb, s); + s->write_cache = 0; ide_reset(s); } } -- 2.30.2